<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>设备编辑</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../static/layui/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
        <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
        <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
    </div>
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


<script src="../../static/layui/layui.js"charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->

<script>
    layui.use('table', function(){
        var table = layui.table;

        //温馨提示：默认由前端自动合计当前行数据。从 layui 2.5.6 开始： 若接口直接返回了合计行数据，则优先读取接口合计行数据。
        table.render({
            elem: '#test'
            ,url:'/test/table/demo1.json'
            ,toolbar: '#toolbarDemo'
            ,title: '设备表'
            ,totalRow: true
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'nuo', title:'设备编号', width:120, fixed: 'left',edit: 'text'}
                ,{field:'classes', title:'类别', width:120, edit: 'text'}
                ,{field:'name', title:'设备名', width:150, edit: 'text'}
                ,{field:'parameter', title:'参数', width:80, edit: 'text'}
                ,{field:'price', title:'价格', width:80, edit: 'text' }
                ,{field:'brith', title:'生产厂商', width:100, edit: 'text'}
                ,{field:'use', title:'用途',width:100, edit: 'text'}
                ,{field:'place', title:'存放地点', width:100, edit: 'text'}
                ,{field:'people', title:'领用人', width:120, edit: 'text'}
                ,{field:'school', title:'学校', width:120, edit: 'text'}
                ,{field:'department', title:'部门', width:120, edit: 'text'}
                ,{field:'remark', title:'备注', width:80, edit: 'text'}
                ,{field:'buytime', title:'购买时间', width:80, edit: 'text'}
                ,{field:'state', title:'状态', width:80, edit: 'text'}
                ,{field:'picture', title:'图片', width:80}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
            ]]
            ,page: true
        });
        //工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：'+ data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选': '未全选')
                    break;
            };
        });
    });
</script>

</body>
</html>